home *** CD-ROM | disk | FTP | other *** search
- // Copyright (C) 1997-2002 Alias|Wavefront,
- // a division of Silicon Graphics Limited.
- //
- // The information in this file is provided for the exclusive use of the
- // licensees of Alias|Wavefront. Such users have the right to use, modify,
- // and incorporate this code into other products for purposes authorized
- // by the Alias|Wavefront license agreement, without fee.
- //
- // ALIAS|WAVEFRONT DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE,
- // INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO
- // EVENT SHALL ALIAS|WAVEFRONT BE LIABLE FOR ANY SPECIAL, INDIRECT OR
- // CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE,
- // DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER
- // TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
- // PERFORMANCE OF THIS SOFTWARE.
- //
- //
- // Alias|Wavefront Script File
- // MODIFY THIS AT YOUR OWN RISK
- //
- // Creation Date: 07 Feb 2001
- // Author: bwk
- //
- // Description:
- // This file implements a generic bitmap browser for all platforms.
- // Note however that the current NT implementation consists of calling
- // the xpmPicker command. Most of the procedures below are for the
- // Irix implementation.
- //
-
- proc string getDirectory()
- //
- // Description:
- // Return the current directory.
- //
- {
- setParent BitmapBrowserWindow;
-
- string $directory;
-
- $directory = `finder -query -filePath BitmapBrowserWindowFinder`;
-
- // Make sure the last character is a "/".
- //
- if (!`gmatch $directory "*/"`) {
- $directory += "/";
- }
-
- return $directory;
- }
-
- proc string getBitmapSelection()
- //
- // Description:
- // Return the current bitmap selection. May return an empty string if
- // there is no selection in the file list.
- //
- {
- setParent BitmapBrowserWindow;
-
- string $selection[], $bitmap = "";
-
- $selection = `textScrollList -query -selectItem
- BitmapBrowserWindowDirectoryList`;
-
- if ("" != $selection[0]) {
- $bitmap = (getDirectory() + $selection[0]);
- }
-
- return $bitmap;
- }
-
- proc updateDirectoryList(string $bitmap)
- //
- // Description:
- // Update the file list control based on the current directory.
- //
- {
- string $directory, $bitmapArray[], $xpmArray[], $bmpArray[];
- int $index, $selectIndex = 0;
-
- setParent BitmapBrowserWindow;
-
- // Remove all the items in the file list control.
- //
- textScrollList -edit -removeAll BitmapBrowserWindowDirectoryList;
-
- // Get the current directory.
- //
- $directory = getDirectory();
-
- // Get all bitmap files in the directory.
- //
- $xpmArray = `getFileList -folder $directory -filespec "*.xpm"`;
- $bmpArray = `getFileList -folder $directory -filespec "*.bmp"`;
-
- // Combine the two lists and sort if necessary.
- //
- int $sort = false;
- if (0 == size($xpmArray)) {
- $bitmapArray = $bmpArray;
- $sort = false;
- } else if (0 == size($bmpArray)) {
- $bitmapArray = $xpmArray;
- $sort = false;
- } else {
- $bitmapArray = AWAppendStringsToStringArray($xpmArray, $bmpArray);
- $sort = true;
- }
- if ($sort) $bitmapArray = sort($bitmapArray);
-
- // Turn on the wait cursor if we have a lot of bitmaps to list.
- //
- if (100 < size($bitmapArray)) waitCursor -state on;
-
- // Append each bitmap to the list.
- //
- for ($index = 0; $index < size($bitmapArray); $index++) {
- textScrollList -edit -append $bitmapArray[$index]
- BitmapBrowserWindowDirectoryList;
-
- // See if the argument bitmap is in the list. If so then
- // record the index so we can scroll the list to show it.
- //
- if ($bitmap == $bitmapArray[$index]) $selectIndex = $index + 1;
- }
-
- if (0 < $selectIndex) {
- //
- // Select the argument bitmap and scroll the list so it is visible.
- //
- textScrollList -edit
- -selectItem $bitmap
- -showIndexedItem $selectIndex
- BitmapBrowserWindowDirectoryList;
- }
-
- // Turn off the wait cursor.
- //
- if (100 < size($bitmapArray)) waitCursor -state off;
- }
-
- proc updatePreview()
- //
- // Description:
- // Update the preview image based on the selected bitmap.
- //
- {
- string $bitmap;
- int $visible = false;
-
- setParent BitmapBrowserWindow;
-
- // Get the current bitmap selection.
- //
- $bitmap = getBitmapSelection();
-
- // If there is no bitmap selected then make sure the image reflects this.
- // Since we can't unassign a bitmap from a control just hide it.
- //
- if ("" != $bitmap) $visible = true;
-
- iconTextStaticLabel -edit
- -image1 $bitmap
- -visible $visible
- BitmapBrowserWindowPreviewImage;
- }
-
- proc bitmapBrowserWindowClose()
- //
- // Description:
- // Safely delete the browser window.
- //
- {
- evalDeferred("deleteUI -window BitmapBrowserWindow");
- }
-
- global proc bitmapBrowserWindow(
- string $bitmap,
- string $callbackProcedure)
- //
- // Description:
- // Show the bitmap browser window.
- //
- //
- // Arguments:
- // $bitmap - The name of the bitmap that you want initially selected
- // in the browser.
- //
- // $callbackProcedure - The procedure that will be called when a bitmap
- // is selected or the the browser is dismissed.
- // The procedure must be defined as follows:
- //
- // global proc yourCallbackProcedure(
- // string $bitmap, // Full path to selected bitmap.
- // int $status // Status of selection, currently unused.
- // )
- //
- // Notes:
- // On NT this simply calls the xpmPicker command which posts a modal
- // dialog.
- //
- // On Irix we create our own window and manage all of the controls.
- //
- {
- if (`about -nt`) {
- string $result = `xpmPicker -fileName $bitmap`;
- int $status = 0;
-
- if ("" != $callbackProcedure) {
- eval ($callbackProcedure + " \"" + $result + "\" " + $status);
- }
- }else if(`about -mac`){
- string $result;
- string $dirName = getenv("MAYA_LOCATION");
- string $matchExpr = "Maya.app/Contents";
-
- string $myString = `substitute $matchExpr $dirName ""`;
- int $status = 0;
-
- $dirName = $myString + "Application Support/extras/icons";
- $dirName = $dirName+"/*.xpm";
- $result = `fileDialog -dm $dirName`;
- if ($result == "") return; // cancel hit
-
- if ("" != $callbackProcedure) {
- eval ($callbackProcedure + " \"" + $result + "\" " + $status);
- }
-
- } else {
- if (!`window -exists BitmapBrowserWindow`) {
-
- waitCursor -state on;
-
- string $window = `window -title "Bitmap Browser"
- -iconName "Bitmaps"
- BitmapBrowserWindow`;
-
- string $form = `formLayout`;
-
- setParent $form;
- string $optionMenu = `optionMenu BitmapBrowserWindowDirectoryOptionMenu`;
- string $finder = `finder -addDropBox false BitmapBrowserWindowFinder`;
- string $bodyForm = `formLayout`;
- string $list = `textScrollList BitmapBrowserWindowDirectoryList`;
- string $frame = `frameLayout -labelVisible false`;
- string $preview = `iconTextStaticLabel -width 128 -height 128
- BitmapBrowserWindowPreviewImage`;
-
- setParent $form;
- string $buttonForm = `formLayout`;
- string $select = `button -label "Select"`;
- string $cancel = `button -label "Cancel"`;
-
- formLayout -edit
- -attachForm $select "top" 0
- -attachForm $select "left" 0
- -attachForm $select "bottom" 0
- -attachPosition $select "right" 2 50
-
- -attachForm $cancel "top" 0
- -attachPosition $cancel "left" 2 50
- -attachForm $cancel "bottom" 0
- -attachForm $cancel "right" 0
- $buttonForm;
-
- formLayout -edit
- -attachForm $list "top" 0
- -attachForm $list "left" 0
- -attachForm $list "bottom" 0
- -attachControl $list "right" 4 $frame
-
- -attachForm $frame "top" 0
- -attachNone $frame "left"
- -attachNone $frame "bottom"
- -attachForm $frame "right" 0
- $bodyForm;
-
- formLayout -edit
- -attachForm $optionMenu "top" 4
- -attachForm $optionMenu "left" 4
- -attachNone $optionMenu "bottom"
- -attachForm $optionMenu "right" 4
-
- -attachControl $finder "top" 4 $optionMenu
- -attachForm $finder "left" 4
- -attachNone $finder "bottom"
- -attachForm $finder "right" 4
-
- -attachControl $bodyForm "top" 4 $finder
- -attachForm $bodyForm "left" 4
- -attachControl $bodyForm "bottom" 4 $buttonForm
- -attachForm $bodyForm "right" 4
-
- -attachNone $buttonForm "top"
- -attachForm $buttonForm "left" 4
- -attachForm $buttonForm "bottom" 4
- -attachForm $buttonForm "right" 4
- $form;
-
- // Populate the option menu with the bitmap directories.
- //
- string $directory, $directoryArray[];
- $directoryArray = `xbmLangPathList`;
- for ($directory in $directoryArray) {
- menuItem -label $directory;
- }
-
- //
- // Attach control commands.
- //
- optionMenu -edit -changeCommand ("bitmapBrowserWindowDirectoryMenuChange") $optionMenu;
- finder -edit
- -filePath $directoryArray[0]
- -command ("bitmapBrowserWindowFinderChange")
- $finder;
-
- textScrollList -edit -selectCommand ("bitmapBrowserWindowListSelect") $list;
-
- button -edit -command ("bitmapBrowserWindowCancel \"" + $callbackProcedure + "\"") $cancel;
- button -edit -command ("bitmapBrowserWindowSelect \"" + $callbackProcedure + "\"") $select;
-
- // See if the supplied bitmap exists. If so then make sure it is
- // selected.
- //
- $directory = locateBitmap($bitmap);
- if ("" != $directory) {
- optionMenu -edit -value $directory $optionMenu;
- finder -edit -filePath $directory $finder;
- }
-
- waitCursor -state off;
-
- updateDirectoryList($bitmap);
- updatePreview();
-
- showWindow $window;
-
- } else {
- // Window already exists.
- showWindow BitmapBrowserWindow;
- }
- }
- }
-
- global proc string locateBitmap(string $bitmap)
- //
- // Description:
- // Find the directory location of a bitmap. The directories searched
- // are specified by the XBMLANGPATH environment variable.
- //
- // Arguments:
- // $bitmap - The name of the bitmap to search for.
- //
- // Returns:
- // Directory containing the bitmap if found, empty string otherwise.
- //
- {
- string $directory = "", $file, $directoryArray[], $fileArray[];
- int $found = false;
-
- if ("" != $bitmap) {
-
- // Get all the directories in the XBMLANGPATH environment variable.
- //
- $directoryArray = `xbmLangPathList`;
-
- for ($directory in $directoryArray) {
- //
- // Make sure the directory ends in a "/" for the getFileList
- // command to work properly.
- //
- if (!`gmatch $directory "*/"`) $directory += "/";
-
- $fileArray = `getFileList -folder $directory`;
-
- // Search for the bitmap.
- //
- for ($file in $fileArray) {
- if ($file == $bitmap) {
- $found = true;
- break;
- }
- }
-
- if ($found) break;
- }
-
- if (!$found) {
- $directory = "";
- }
- }
-
- return $directory;
- }
-
- global proc bitmapBrowserWindowDirectoryMenuChange()
- //
- // Description:
- // This procedure is called whenever the user changes the value of the
- // directory option menu.
- //
- // Update the finder control, file list and preview image.
- //
- {
- string $directory;
-
- $directory = `optionMenu -query -value BitmapBrowserWindowDirectoryOptionMenu`;
-
- finder -edit -filePath $directory BitmapBrowserWindowFinder;
-
- updateDirectoryList("");
- updatePreview();
- }
-
- global proc bitmapBrowserWindowFinderChange()
- //
- // Description:
- // This procedure is called whenever the user changes the value of the
- // finder control.
- //
- // Update the file list and preview image.
- //
- {
- updateDirectoryList("");
- updatePreview();
- }
-
- global proc bitmapBrowserWindowListSelect()
- //
- // Description:
- // This procedure is called whenever the user changes the selection in
- // the file list.
- //
- // Update the preview image.
- //
- {
- updatePreview();
- }
-
- global proc bitmapBrowserWindowCancel(string $callbackProcedure)
- //
- // Description:
- // This procedure is called whenever the user selects the Cancel button.
- //
- // Invoke the callback procedure and close the browser.
- //
- {
- string $bitmap;
- int $status = 0;
-
- if ("" != $callbackProcedure) {
- eval ($callbackProcedure + " \"\" " + $status);
- }
-
- bitmapBrowserWindowClose();
- }
-
- global proc bitmapBrowserWindowSelect(string $callbackProcedure)
- //
- // Description:
- // This procedure is called whenever the user selects the Select button.
- //
- // Invoke the callback procedure and close the browser.
- //
- {
- string $bitmap;
- int $status = 0;
-
- if ("" != $callbackProcedure) {
- $bitmap = getBitmapSelection();
-
- eval ($callbackProcedure + " \"" + $bitmap + "\" " + $status);
- }
-
- bitmapBrowserWindowClose();
- }
-